package cn.yusei.teamTribe.service.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yusei.teamTribe.constant.ResponseCode;
import cn.yusei.teamTribe.dao.user.UserInfoDAO;
import cn.yusei.teamTribe.dao.user.po.UserInfoPO;
import cn.yusei.teamTribe.exception.UserIdNotFoundException;

@Service
public class UserInfoService {

	@Autowired
	private UserInfoDAO userInfoDAO;
	
	public UserInfoPO get(int id)
	{
		UserInfoPO userInfoPO = userInfoDAO.select(id);
		if(userInfoPO == null)
			throw new UserIdNotFoundException("用户Id [" + id + "] 不存在");
		return userInfoPO;
	}
	
	public int update(UserInfoPO user)
	{
		if(userInfoDAO.select(user.getId()) == null)
			return ResponseCode.USER_NOT_EXISTS;
		userInfoDAO.update(user);
		return ResponseCode.REQUEST_SUCCESSED;
	}
	
	public int updateAuth(UserInfoPO user)
	{
		if(userInfoDAO.select(user.getId()) == null)
			return ResponseCode.USER_NOT_EXISTS;
		userInfoDAO.updateAuth(user);
		return ResponseCode.REQUEST_SUCCESSED;
	}
	
}
